package com.sky.utils;

import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import java.util.Set;

@Component
@Data
public class CleanCacheUtil {
    @Autowired
    private RedisTemplate redisTemplate;

    /**
     * 清理缓存数据
     */
    public void  cleanCache(String pattern) {
        Set<String> keys = redisTemplate.keys(pattern);
        if (keys != null && !keys.isEmpty()) {
            redisTemplate.delete(keys);
        }
    }
}
